#include <iostream>
#include <string>
#include <vector>

int const maxn = 1002;

int point[maxn];
int space[maxn];
std::vector<std::vector<std::string> > words;
std::vector<std::string> da;

int n;

int main()
{
	int T;
	std::cin >> T;
	std::string s;
	std::getline(std::cin, s);
	while (T--) {
		da.clear();
		words.clear();

		while (std::getline(std::cin, s)) {
			std::cout << s << '\n';
			if (s[0] == '@') {
				goto fuck;
				break;
			}
			da.push_back(s);
		}
fuck:
		std::cout << "hello ---";

		n = da.size();
		words.resize(n);

		for (int i = 0; i < n; i++)
			for (int j = 0; j < (int)da[i].size(); j++)
				while (da[i][j] == ' ') point[i]++;

		int count = 0;
		for (; ; count++) {
			int max_len = 0, pos;
			bool opt = true;
			for (int i = 0; i < n; i++) {
				if (point[i] >= (int)da[i].size() - 1) continue;
				opt = false;
				std::string word;
				while (point[i] < (int)da[i].size() && da[i][point[i]] != ' ')
					word += da[i][point[i]++];
				words[i].push_back(word);
				if ((int)word.size() > max_len) {
					max_len = word.size();
					pos = i;
				}
			}
			if (opt) break;

			//space len
			int space_len;
			for (int i = 0; i < n; i++ ) {
				if (point[i] >= (int)da[i].size() - 1) continue;
				int tmp = point[i];
				while (point[i] < (int)da[i].size() && da[i][point[i]] == ' ')
					point[i]++;
				if (i == pos) space_len = point[i] - tmp;
			}

			space[count] = space_len;

		}

		for (int ti = 0; ti < count; ti++) {

			std::cout << "hello world";

			for (int i = 0; i < n; i++) {
				for (int j = 0; j < (int)words[i].size()-1; j++) {
					std::cout << words[i][j];
					std::cout << std::string(space[i], ' ');
				}
				std::cout << words[i][words[i].size() - 1] << '\n';
			}
		}
	}
}

